import matplotlib.pyplot as plt
import numpy as np
import os

def CompRatio():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    ind = np.arange(len(x_data))
    y_data1 = [0.840153402793172, 0.9763307470627355, 0.9771502992684548, 0.853086455331412, 0.9752868543560186, 0.9752868543560186, 0.9744273996896474, 0.9493509199733984, 0.965548880514298, 0.8487840833518067, 0.43547727776546225, 0.43324983373974746]
    y_data2 = [0.8188760806916426, 0.9690312569275106, 0.9751052981600532, 0.8165595211704721, 0.969164265129683, 0.969164265129683, 0.9659055641764576, 0.9401906450897806, 0.9554422522722235, 0.8186211483041455, 0.41387718909332744, 0.41254710707160275]
    w = 0.2
    ax = plt.subplot(111)
    a = ax.bar(ind,y_data1,width=0.2,align='center')
    b = ax.bar(ind+w,y_data2,width=0.2,align='center')
    ax.set_xticks(ind+w)
    ax.set_xticklabels( ('MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF') )
    plt.legend((a,b),('ave CompRatio','worst CompRatio'))
    plt.autoscale(tight=True)
    plt.title('The average/worst CompRatio')
    plt.tight_layout()
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    CompRatio()